#!/bin/bash
# Created by tao.zeng on 2022/03/29.
# Usage: sh to_kafka.sh topic dataFile [brokerList]

BASE_DIR=$(cd `dirname $0`;pwd)
DEFAULE_BROKER_LIST=192.168.103.127:9092

TOPIC=$1
DATA_FILE=$2
BROKER_LIST=$3

# 判断topic和数据文件不为空
[[ -z $TOPIC || -z $DATA_FILE ]] && echo " Uasge: sh $0 <topic> <dataFile> [borker-list]" && exit 1

# 判断broker list，设置默认值
[[ -z $BROKER_LIST ]] && BROKER_LIST=${DEFAULE_BROKER_LIST}

echo -e "---------------------------------------- \
        \n\tbrokerList: $BROKER_LIST \
        \n\ttopic: $TOPIC \
        \n\tdataFile: $DATA_FILE \
        \n----------------------------------------"

# 发送数据到kafka
cat ${DATA_FILE}|kafka-console-producer.sh --broker-list ${BROKER_LIST} --topic ${TOPIC}

